package com.luzhikun.aSynchronouseListener_1;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author Rookie Coder
 * @Description
 * @Date
 **/
public class SunRunnable implements Runnable{
    private AsyncContext as;
    public SunRunnable(AsyncContext as) {
        this.as=as;
    }

    @Override
    public void run() {
        // 获取请求对象
        HttpServletRequest request = (HttpServletRequest) as.getRequest();
        // 获取session对象
        HttpSession session = request.getSession();
        int sum=0;
        try {
            for (int i = 0; i < 10; i++) {
                // 休眠1000毫秒
                Thread.sleep(1000);
                sum+=i;

                System.out.println(i);
            }
            // 设置session属性值
            session.setAttribute("sum",sum);
//            as.complete();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
